@extends('web.layouts.app')
@section('styles')
    <link rel="stylesheet" type="text/css" href="{{ asset('resources/web/css/products-detail.css')}}">
    <link rel="stylesheet" type="text/css" href="{{ asset('resources/web/css/ucenter.css')}}">
    <link rel="stylesheet" type="text/css" href="{{ asset('resources/web/css/base.css')}}">
    <link rel="stylesheet" type="text/css" href="{{ asset('resources/web/css/shenhe.css')}}">
@endsection
@section('content')
    <!--container-->
    <div class="container mt20 pt10 wrap clearfix" style="padding-top: 0px;margin-top: 0px;">
        <div class="bread-nav">
             <a href="/user/settings">我的账户</a><i>&gt;</i>
             <a href="/Guarantee/index">担保管理</a><i>&gt;</i>
             <span>项目详情</span>
        </div>
        <div class="detail-main L">
            <!--project info-->
            <div class="project-box">
                <div class="project-title">
                    <h1>{{$project->projects_name}}</h1>
                    @if($project->new_projects)
                    <i class="tips">新手标</i>
                    @endif
                    <!-- <span class="R"><img src="{{asset('resources/web/images/detail_indem.gif')}}" height="16" width="14">100%本息保障</span> -->
                </div>
                <div class="project-info clearfix">
                    <dl class="item-col">
                        <dt>借款金额</dt>
                        <dd><em>{{$project->finance_money}}</em><span>{{$project->money_cate}}</span></dd>
                    </dl>
                    <!--年化收益利率放到 data-rate里，jquery通过这个属性获取值来计算，具体算法根据实际情况改-->
                    <dl class="item-col" id="J_project_rate">
                        <dt>年化收益</dt>
                        <dd><em>{!! $project->auto_rate !!}</em></dd>
                    </dl>
                    <!--项目时间-->
                        <dl class="item-col" id="J_project_days">
                            <dt>项目期限</dt>
                            <dd>
                                <em>{{$project->finance_time_num}}</em>
                                @if($project->finance_time_cate=='d')
                                <span>天</span>
                                @elseif($project->finance_time_cate=='m')
                                <span>个月</span>
                                @elseif($project->finance_time_cate=='mm')
                                <span>个自然月</span>
                                @endif
                            </dd>
                        </dl>
                </div>
                <ul class="project-info-prop clearfix">
                    <li class="col-md">起投金额：<em>{{number_format($project->finance_rule_money,2)}} 元</em></li>
                    <li class="col-sm">已投金额：<em>{{number_format($project->financed_money,2)}} 元</em></li>
                    <li class="col-md">还需借款：<em>{{number_format($project->finance_money-$project->financed_money,2)}} 元</em></li>
                    <li class="col-md">担保公司：<em>{{$project->suretyCompany()->company_name}}</em></li>
                    <li class="col-sm">担保方式：<em>{{$project->suretyWay()->name}}</em></li>
                    <li class="col-md">还款方式：<em>{{$project->repayment()->name}}</em></li>
                    <li class="col-md">红包活动：
                      <em>{{$gift??'暂无活动'}}</em>
                    </li>
                </ul>
            </div>
            <!--project info /-->
            <!--project content-->
            <div class="project-content">
                <div class="project-content-menu">
                    <ul class="clearfix">
                        @if(@type_attr)
                            @foreach($type_attr as $key=>$item)
                                <li class="{{$key==0?'active':''}}">{{$item->attr_name}}</li>
                            @endforeach
                        @endif
                        <li>投资明细</li>
                    </ul>
                </div>
                <div class="project-content-box">
                    <!--项目信息-->
                    @if(@type_attr)
                        @foreach($type_attr as $key=>$item)
                            @if($item->cate)
                                <div class="papers {{$key==0?'':'hide'}}">
                                    @foreach(json_decode($item->content) as $img)
                                        <div class="img">
                                            <a href="javascript:;">
                                                <img src="{{$img->full_url}}">
                                                <span>{{$img->filename}}</span>
                                            </a>
                                        </div>
                                    @endforeach
                                </div>
                            @else
                                <div class="project-description {{$key==0?'':'hide'}}">{!! $item->content !!}</div>
                                @endif
                                @endforeach
                                @endif
                                <!--投资列表-->
                                <div class="invest-list hide">
                                    <ul class="invest-table">
                                        <li class="th">
                                            <span class="col-sm">序号</span>
                                            <span class="col-md">投资人</span>
                                            <span class="col-md">投资金额(元)</span>
                                            <span class="col-md">投资时间</span>
                                        </li>
                                        @forelse($invest as $key=>$item)
                                            <li class="td">
                                                <span class="col-sm">{{$key+1}}</span>
                                                <span class="col-md">{{str_hide($item->user_name)}}</span>
                                                <span class="col-md">{{$item->invest_money}}</span>
                                                <span class="col-md">{{$item->invest_time}}</span>
                                            </li>
                                        @empty
                                            <li class="td">
                                                暂无投资记录
                                            </li>
                                        @endforelse
                                    </ul>
                                    {{$links}}
                                </div>
                </div>
            </div>
            <!--project content /-->
        </div>
        <div class="shenhe-side R">
            <div class="project-status-bar" {{$project->checkFull()}}>
                <h2 class="title">项目状态</h2>
                @if($project->checkFull())
                <form action="/guarantee/check/{{$project->id}}" method="post" class="content">
                    {{ csrf_field() }}
                    <div class="status-bar">满标审核</div>
                    <p class="mt10">操作事项：</p>
                    <p>
                        <i class="icon-light"></i>1. 生成借款合同 
                        @if(empty($project->projects_file))
                        <a class="pl10" id="agreement" href="javascript:;">立即生成</a>
                        @else
                        <span {{$project->projects_file}}>已生成</span>
                        @endif
                    </p>
                    <p>审核密码：<input type="password" name="password" class="txt" placeholder="请输入密码" required/></p>
                    <div class="text-center">
                        <input class="btn orange-bg" type="submit" value="确认">
                        <input class="btn gray-bg" type="reset" value="取消">
                    </div>
                </form>
                @else
                <div class="status-bar doing">{{$project->status()->name}}</div>
                @endif
            </div>
            <!-- 审核记录 -->
            <div class="project-shenhe-log mt20">
                <h2 class="title">审核记录</h2>
                <div class="content">
                    <dl>
                        <dt>审核记录</dt>
                        @forelse($project_check as $item)
                        <dd>{{$item->username}},{{$item->input_time}}</dd>
                        @empty
                        <dd>无审核记录</dd>
                        @endforelse
                    </dl>
                </div>
            </div>
        </div>
    </div>
    <!--container /-->
    @endsection
@section('scripts')
<script type="text/javascript" src="{{asset('resources/web/js/jquery.min.js')}}"></script>
<script type="text/javascript" src="{{asset('resources/web/js/shenhe.js')}}"></script>
<script type="text/javascript" src="{{asset('resources/web/plugins/datePicker/WdatePicker.js')}}"></script>
<script type="text/javascript">
$(function(){
  var timer,bol=false; 
  $("#agreement").click(function(){
    var obj=$(this);
    $("[type=submit]").attr("disabled","disabled").val("正在生成合同");
    $.get("/guarantee/createAgreement/{{$project->id}}").success(function(data){
      if(data=='1'){
        obj.before('&nbsp;&nbsp;&nbsp;<span>已生成</span>');
        obj.remove();
        setTimeout(function() {
          $("[type=submit]").removeAttr("disabled").val("确认");
        }, 3000);
      }else{
        alert('封包出错！'+data);
      }
    });
  });
})
</script>
@endsection